added Feb 2001 SDK
[windows-sources.git] / shared source / vb / language / shared / iiterator.h
blob23ff237a7f94d00e25776d6ba9e3e5a2a167024b
1 //-------------------------------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 //-------------------------------------------------------------------------------------------------
7 #pragma once
10 template <class T>
11 class IIterator : public virtual IConstIterator<T>
13 public:
14 virtual
15 ~IIterator()
19 virtual
20 void Remove() = 0;
23 template <class T>
24 class Iterator : public virtual IIterator<T>
26 public:
27 Iterator()
31 explicit Iterator(RefCountedPtr<IIterator<T> > spIterator)
32 : m_spIterator(spIterator)
37 template <class U>
38 Iterator(const U& it)
40 m_spIterator.Attach(new (zeromemory) U(it));
43 virtual __override
44 bool MoveNext()
46 if ( m_spIterator )
48 return m_spIterator->MoveNext();
50 else
52 // NULL is used to represent an empty iterator
53 return false;
57 virtual __override
58 T Current()
60 ThrowIfFalse2(m_spIterator, "Current called on an empty iterator");
61 return m_spIterator->Current();
64 virtual __override
65 void Remove()
67 ThrowIfFalse2(m_spIterator, "Remove called on an empty iterator");
68 m_spIterator->Remove();
71 private:
72 // Allow default copy constructor and assignment operators to
73 // be generated because RefCountedPtr is copy safe
74 RefCountedPtr<IIterator<T> > m_spIterator;